Repository navigation
madmatrix GPU: size wavefunction arrays by slots used, stop big fast-math compiles - #511
Merged
Merged
Conversation
nwf counts calls, slots reused: ttggg 121 not 391, barrier only with shared slots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fast math never picked there, dense arrays make its ptxas take over an hour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
Compile timeUpdate: the numbers in this section are for 0b95a6d. The variant prediction (695991a) and the barrier masks (f96ceb9) are now in this PR, final numbers at the end. Clean builds of
L40S run time,
|
d |
f |
v |
|
|---|---|---|---|
g g > t t~ g g g |
0.89 at 256×256 (#491 fails at 512×256) | 1.22 ± 0.006 | 1.30 ± 0.003 |
g g > t t~ + 0–2g |
0.998–1.000 | 0.998–1.000 | 0.998–1.017 |
ttgggdwith madmatrix: wavefunctions in GPU shared memory, SHAREDWF=auto by spill #491 needs 68 KB of stack per thread and stops with a CUDA error at 512×256 on L40S (it runs at 256×256). With this PR it needs 34 KB and runs, but FP64 has no shared slots on L40S and the smaller arrays give 5× more local loads, so it is 0.89× where both run.- |M|² bitwise identical except
ttggg(≤ 1.96e-6f/v, ≤ 1.25e-14d), helicity and colour choices identical, sameSHAREDWF/FASTMATHpicks.
With the prediction and the barrier masks
Separate side-by-side run with the same method (main and #491 differ by up to 13% from the run above), wall / CPU seconds:
| main | #491 | this PR | |
|---|---|---|---|
H100 f |
577 / 860 | 1650 / 5863 | 652 / 947 |
H100 v |
606 / 882 | 1583 / 6038 | 570 / 872 |
H100 d |
400 / 670 | 1301 / 5106 | 436 / 712 |
L40S f |
493 / 717 | 1350 / 5023 | 386 / 625 |
L40S v |
523 / 766 | 1323 / 4962 | 262 / 522 |
L40S d |
387 / 608 | 1113 / 4498 | 200 / 432 |
- Prediction: outside a band of amplitude counts (
dbelow 10 / above 30,f/vbelow 21 / above 130) only the predicted variant is compiled, sottgggis compiled once. 234 picks on L40S, H100 and sm_70/80/100 builds, none missed; the band now includesg g > t t~ g g. Alone it halves the CPU time (H100f2755 → 1356 s) and moves wall time little, since the singlettgggcompilation is the critical path. - Barrier masks: the remaining barriers cost the
ttgggcompilation most of its cicc time; keeping only the 819 (L40Sf) / 1245 (H100f) of 1890 that a later shared read needs takes thettgggbuild from 960 to 379 s wall on L40S. - Together the gated build is at main's compile time: 0.88–1.06× main's speed on H100 (wall), 1.3–2.0× faster than main on L40S, 2.5–5.6× wall / 6.2–10.4× CPU faster than madmatrix: wavefunctions in GPU shared memory, SHAREDWF=auto by spill #491.
🤖 Generated with Claude Code
Smaller arrays, no barrier there: L40S FP64 ttggg 0.89x, ttgQQ 0.985x. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compile time over L40S FP64 run time, FP64 not target there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Picks follow amplitude count, GPU-independent outside band, 234 picks none missed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generator mask per barrier, bit per nSharedWf, constexpr no-op otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
stloufra
added a commit
that referenced
this pull request
Nov 22, 2026
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #491 (shared-memory wavefunctions), which is stacked on #486 (
FASTMATH=auto).calculate_jampsofg g > t t~ g g g(1240 diagrams, 1890 amplitudes) spills ~40 KB per thread and takes 20–40 min to compile with #491. This PR makes it faster at run time and cheaper to compile. The one exception is FP64 on GPUs that give it no shared-memory slots (L40S), see below.Changes
Wavefunction arrays sized by the slots used.
nwfcounts wavefunction calls, butEvaluateDiagrams.increuses slots:ttgggindexes 121 of 391. The generator now emitsnWfSlots(highestaloha_objindex + 1) inSharedWavefunctions.inc, and the GPUcalculate_jampssizespvec_sv/w_sv/aloha_objby it. Unused slots still cost local memory and stores.SHWF_RELOADonly where a shared slot is read again. The compiler barrier after each amplitude is needed only when wavefunctions live in shared memory, and then only between two accesses of a shared slot. The generator now gives each barrier a mask, bit n−1 set when it is needed withnSharedWf= n (the one closest to the read is kept), and the macro is a constexpr no-op otherwise. Without shared slots none is left;ttgggfkeeps 819 of 1890 on L40S and 1245 on H100. Each barrier costs cicc time: on L40S the keptttgggfcompilation goes from 858 to 259 s of cicc; on H100 cicc 1436 → 1302 s. |M|² is bitwise identical. The dropped barriers also no longer fence the spill code, so the scheduler places it differently: on L40Sttgggruns 1.010× infand 0.958× inv(20 repetitions, 0.953 at 512×256), on H100 nothing changes.Fast-math compile stopped for big FP32 kernels. With
FASTMATH=auto, once a side's-fmadbuild spills more thanFASTMATH_MAD_STACK(4096 B) forFPTYPEinFASTMATH_CUTOFF_FPTYPES(f v), its-use_fast_mathnvcc is killed and-fmadis kept. Fast math only ever won below 1.2 KB (96 picks, L40S and H100), and with the smaller arrays its approximate division takes ptxas from minutes to over an hour onttggg.Variants predicted from the amplitude count. With
SHAREDWF=auto/FASTMATH=autoandFPTYPEd/f/v, the picks follow the number of amplitudes inEvaluateDiagrams.incand are the same on every GPU outside a band (234 picks on L40S, H100 and sm_70/80/100 builds, none missed):dwithout shared memory below 10, with it above 30, always-use_fast_math;f/vwithout shared memory and with fast math below 21, with shared memory above 130,-fmadabove 300. Only the predicted variant is compiled there; inside the band the gate compiles and measures as before.AUTO_PREDICT=0compiles all of them.Run time
check_sa perf, ME call + sync, 10 interleaved repetitions, paired median,SHAREDWF=auto FASTMATH=autoon both sides. Throughput of this PR over #491:dfvdfvg g > t t~ g g gg g > t t~+ 0–2gl+l-+ 3jW+W-+ 3j (FD)ttgggon L40S (|M|² bitwise identical, same picks, 10 repetitions at the combo launch sizes).g g > t t~+ 0–3g at 512×256,l+l-+ 3j at 2048×256,W+W-+ 3j at 1024×256. Spread ≤ 0.006.ttggg(stack 39–69 KB → 13–34 KB),g q > W+ W- q q q~ind(7.5 → 5.3 KB) and, on L40Sd,g g > t t~ g Q Q~(0.99×).d, at 256×256. FP64 gets no shared-memory slots on sm_89, and there the smaller arrays halve the stack (68 → 34 KB) but give 5× more local loads. With madmatrix: wavefunctions in GPU shared memory, SHAREDWF=auto by spill #491,ttgggdstops with a CUDA error at 512×256 on L40S; with this PR it runs. Accepted: L40S is not meant for FP64. Keeping madmatrix: wavefunctions in GPU shared memory, SHAREDWF=auto by spill #491's arrays and the barrier without shared slots (82c4276, reverted) brings L40Sdback to 1.00 but takes most of the compile saving:f/vonly 1.09–1.32× wall faster than madmatrix: wavefunctions in GPU shared memory, SHAREDWF=auto by spill #491 instead of 1.25–1.53×,d0.98–1.07× instead of 1.12–5.0× (both before the prediction and the barrier masks).Correctness. Same
SHAREDWF/FASTMATHpicks as #491 in every subprocess. |M|² bitwise identical exceptttggg(≤ 2e-6f/v, ≤ 1.3e-14d, reordered spills). Helicity and colour choices identical (uniform--rnd-hel/--rnd-col).Compile time
Clean builds of
g g > t t~+ 0–3g (make -j8, CUDA 13.1), the three builds of each FPTYPE side by side, wall / CPU seconds. #491 and this PR withSHAREDWF=auto FASTMATH=auto, main with its defaults.fvdfvdThe gated build is back at main's compile time:
ttgggis compiled once, with fewer barriers and smaller arrays. Step by step (sizing and fast-math stop, then the prediction) in the comment below.🤖 Generated with Claude Code